<template>
	<view>
		<scroll-view scroll-y="true">
			<view class="topbg">
				<view class="userView weui-flex">
					<view>
						<view class="placeholder" style="width: 190upx;" @tap="navsigln()">
							<image class="userimg" :src="getAvatarUrl(userData.avatarUrl)"></image>
							<view class="ellipsis">
								<view>{{userData.nickName}}</view>
							</view>
						</view>
					</view>
					<view>
						<view class="placeholder  beanstyle" @click="navHealthbeans">
							<view class="title">
								{{allBean}}
							</view>
							健康豆
						</view>
					</view>
					<view>
						<view class="placeholder beanstyle" @click="navDiscounts">
							<view class="title">
								{{totalCount}}
							</view>
							优惠券
						</view>
					</view>
					<view>
						<view class="placeholder" @tap="tapnews">
							<view class="newsStyle">
								<view class="newsStylebf" v-if="informationNum!=0">
									{{informationNum}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="body_m">
				<view class="titlegl">
					健康管理
				</view>
				<u-line class="u-line" color="#EEEEEE"></u-line>
				<view>
					<block v-for="(item,idx) in healthList" :key="idx">
						<view class="health" @tap="health(item,idx)">
							<image class="healthImg" :src="item.image"></image>
							{{item.title}}
						</view>
					</block>
				</view>
			</view>
			<view class="body_m">
				<view class="titlegl">
					常用工具
				</view>
				<u-line class="u-line" color="#EEEEEE"></u-line>
				<view>
					<block v-for="(item,idx) in toolArr" :key="idx">
						<view class="health" @tap="toPage(item,idx)">
							<image class="healthImg" :src="item.image"></image>
							{{item.title}}
						</view>
					</block>
				</view>
			</view>
			<view class="body_m">
				<view class="titlegl">
					我的圈子
				</view>
				<u-line class="u-line" color="#EEEEEE"></u-line>
				<view>
					<block v-for="(item,idx) in circleList" :key="idx">
						<view class="health" @tap="circle(item,idx)">
							<image class="healthImg" img-mode="aspectFill" :src="item.image"></image>
							{{item.title}}
						</view>
					</block>
				</view>
			</view>
			<view style="height: 60upx;">
			</view>
		</scroll-view>
		<dev-button v-show="false"></dev-button>
	</view>
</template>

<script>

import uLine from "@/uview-ui/components/u-line/u-line.vue"

	export default {
		components: {
			uLine,
		},
		data() {
			return {
				totalCount: 0, //优惠券数量
				userData: {
					avatarUrl: 'http://static.bsyjk.cn/l/65872593C2124F8381198C89479F28D6.png',
					nickName: '立即登录',
				}, //用户信息
				allBean: 0, //总豆
				informationNum: 0, //消息数量
				healthList: [{
						image: 'http://static.bsyjk.cn/record/DACC765552F041DBA910E3C651847AE2.png',
						title: '健康档案',
					},
					{
						image: 'http://static.bsyjk.cn/report/2E4D2F72A12441EDB26BCD136C328EA1.png',
						title: '健康报告',
					},
					{
						image: 'http://static.bsyjk.cn/plan/4EBDAE0EC65D405298AA95F44B6B98DD.png',
						title: '健康计划',
					},
					{
						image: 'http://static.bsyjk.cn/family/B7F5CCC4BEC848F094DAA34C2F414E42.png',
						title: '我的家人',
					},
					{
						image: 'http://static.bsyjk.cn/bodyche/26FEE574761145488618A59E2F117AAE.png',
						title: '人体成分',
					}
				],
				toolArr: [{
						image: 'http://static.bsyjk.cn/experienceMd/5096801B81A64AEC9669C53983A1190E.png',
						title: '门店体验',
					},
					{
						image: 'http://static.bsyjk.cn/collect/766432FD60044B35B4B677C1FE77B6F5.png',
						title: '我的收藏',
					},
					{
						image: 'http://static.bsyjk.cn/equipment/C4F4302BF6E1432C8ADB20A048505309.png',
						title: '我的设备',
					},
					{
						image: 'http://static.bsyjk.cn/SigninImage/BC29BCC2ABC34BDEA00618747648DE4C.png',
						title: '我的签到',
					},
					{
						image: 'http://static.bsyjk.cn/myyq/2600C55C3B9D4A779A45D5603621AD88.png',
						title: '我的推广',
					},
					// {
					// 	image: 'http://static.bsyjk.cn/contrastBg/59D49CFB31234F7DB4391D3476E1E8BE.png',
					// 	title: '报告对比',
					// },
					{
						image: 'http://static.bsyjk.cn/counselor/B65F9B87D520455BB4B936BCDE624BDC.png',
						title: '我的顾问',
					},
					{
						image: 'http://static.bsyjk.cn/coupleBack/8ADCF71D688C4D15B1B0EE0127316B70.png',
						title: '帮助与反馈',
					},
					{
						image: 'http://static.bsyjk.cn/setting/6E0D0174D9FF4FE98A256AE61B78B29B.png',
						title: '设置',
					},
					// {
					// 	image: '',
					// 	title: '扫一扫',
					// }
				],
				circleList: [{
					image: 'http://static.bsyjk.cn/myHomepage/4EC4891B035C4466B9D193653FE48018.png',
					title: '我的主页',
				}, {
					image: 'http://static.bsyjk.cn/attention/A629E08D0695474E8C649AC6EF6CDACA.png',
					title: '我的关注',
				}, {
					image: 'http://static.bsyjk.cn/beanVermicelli/23334B5A5E424264B27F02C86C4C2179.png',
					title: '我的粉丝',
				}]
			}
		},
		onShow() {
			console.log(global.userInfo, 'lou')
			// 未登录不调用接口
			if (global.token != '') {
				this.upvoteRecord() //获取用户信息
				this.myCount() //消息
				this.getUserPointTotal() //总豆
				this.getCouponPageByWid([1], 1, 1) //获取优惠券数量
			}
		},
		onPullDownRefresh() {
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
			if (global.token != '') {
				this.upvoteRecord() //获取用户信息
				this.myCount() //消息
				this.getUserPointTotal() //总豆
				this.getCouponPageByWid([1], 1, 1) //获取优惠券数量
			}
		},
		methods: {
            //获取用户头像
            getAvatarUrl(avatarUrl){
                if(avatarUrl==null || (avatarUrl.indexOf("qlogo") !=-1 && avatarUrl.indexOf("9VemZoJ8rg") != -1) ){
                    return global.DEFAULT_AVATARURL
                }
                return avatarUrl;
            },
			// 点击头像去登录
			navsigln() {
				this.$basejs.globaltoken()
				if (!global.token) {
					return;
				}
				uni.navigateTo({
					url: '/pagesMy/my/settingUp/accountsetting'
				})
			},
			// 获取优惠券
			getCouponPageByWid(statusRange, pageCurrent, pageSize) {
				let _this = this;
				this.$https.get(global.apiUrls.getCouponPageByShop, {})
					.then(res => {
						if (res.data.code == 1000) {
							_this.totalCount = res.data.result.un_use_num
						}
					})
			},
			// 获取头像昵称
			upvoteRecord() {
				uni.showLoading({
					title: '加载中',
					duration: 2000
				});
				let _this = this;
				this.$cms.get(global.apiUrls.upvoteRecord + '?userId=' + uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z').userId, {})
					.then(res => {
						if (res.data.code == 1000) {
							let result = res.data.result;
							console.log(result,229999999990)
							_this.userData = result;
							global.userInfo.avatarUrl = res.data.result.avatarUrl;
							uni.hideToast(); //隐藏
						}
					}).catch(err => {})
			},
			// 获取用户总积分
			getUserPointTotal() {
				let _this = this;
                if(global.IS_BSY_SHOP){
                    this.$https.get(global.apiUrls.getHealthyBeans).then(res => {
                      _this.allBean = res.data.consum_point
                    })
                }else{
                   this.$shopnew.get(global.apiUrls.getUserPointTotal + '?userId=' + uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z')
                   	.userId, {}).then(res => {
                   	if (res.data.code == 1000) {
                   		_this.allBean = res.data.result
                   	}
                   })
                }

			},
			// 获取消息条数
			myCount() {
				let _this = this;
				this.$cms.get(global.apiUrls.myCount, {sourceType:1})
					.then(res => {
						if (res.data.code == 1000) {
							let result = res.data.result;

							_this.informationNum = result.comment += result.fans += result.like += result.system; //总数
						}
					})
			},
			circle(item, idx) {
				this.$basejs.globaltoken()
				if (!global.token) {
					return;
				}
				if (idx == 0) {
					uni.navigateTo({
						url: '/pagesMy/my/homepage/homepage'
					})
				} else if (idx == 1) {
					uni.navigateTo({
						url: '/pagesMy/my/myinterest/myinterest?type=' + 1
					})
				} else if (idx == 2) {
					uni.navigateTo({
						url: '/pagesMy/my/beanvermicelli/beanvermicelli'
					})
				}
			},
			toPage(item, idx) {
				this.$basejs.globaltoken()
				if (!global.token) {
					return;
				}
				if (idx == 0) {
					uni.navigateTo({
						url: '/pagesMy/my/experience/experience'
					})
				} else if (idx == 1) {
					uni.navigateTo({
						url: '/pagesMy/my/collect/collect'
					})
				} else if (idx == 2) {

					uni.navigateTo({
						url: 'plugin-private://wxe3d2a6ab8dd5b49b/pages/device/mylist/index'
					})
				}else if (idx == 3) {
					// uni.navigateTo({//报告对比
					// 	url: '/pagesMy/my/comparison/comparison'
					// })
					uni.navigateTo({
						url:'/pages/subpackage/SignIn/SignIn'
					})
				} else if (idx == 4) {
					uni.navigateTo({
						url: '/pagesMy/my/promotionDetails/index'
					})
				} else if (idx == 5) {
					uni.navigateTo({
						url: '/pagesMy/my/counselor/counselor'
					})
				} else if (idx == 6) {
					uni.navigateTo({
						url: '/pagesMy/my/feedback/feedback'
					})
				} else if (idx == 7) {
					uni.navigateTo({
						url: '/pagesMy/my/settingUp/settingUp'
					})
				}else if(idx == 8){
					wx.scanCode({
					  success (res) {
					    console.log(res,'298888888888888888888888')
						// uni.navigateTo({
						// 	url:'/'+res.path
						// })
					  }
					})
				}
			},
			health(item, idx) {
				this.$basejs.globaltoken()
				if (!global.token) {
					return;
				}
				if (idx === 0) { //健康档案
					uni.navigateTo({
						url: '/pagesMy/health-records/health-records'
					})
				} else if (idx === 1) {
					// uni.navigateTo({
					// 	url: '/pages/subpackage/home/HealthReport/HealthReport?pageMy=1'
					// })
					uni.navigateTo({
						url: '/pagesMy/health-records/my-report'
					})
				} else if (idx == 2) {
					uni.navigateTo({
						url: '/pagesHome/health-assessment/health-plan'
					})
				} else if (idx == 3) {
					uni.navigateTo({
						url: '/pagesMy/my/family/family'
					})
				}else if (idx == 4){
					uni.navigateTo({
						url: '/subpackage/bodyFatScale/bodyFatScale'
					})
				}
			},
			navDiscounts() {
				this.$basejs.globaltoken()
				if (!global.token) {
					return;
				}
				uni.navigateTo({
					url: '/pagesMy/my/discounts/discounts'
				})
			},
			navHealthbeans(e) {
				this.$basejs.globaltoken()
				if (!global.token) {
					return;
				}
				uni.navigateTo({
					url: '/pagesMy/my/healthBeans/healthBeans'
				})
			},
			tapnews(e) {
				this.$basejs.globaltoken()
				if (!global.token) {
					return;
				}
				uni.navigateTo({
					url: '/pagesMy/my/news/news'
				})
			}
		}
	};
</script>
<style lang="scss" scoped>
	.health {
		display: inline-block;
		width: 178upx;
		height: 172upx;
		text-align: center;

		.healthImg {
			width: 40upx;
			height: 40upx;
			text-align: center;
			display: block;
			margin: 40upx auto 10upx;
		}
	}

	.body_m {
		width: 718upx;
		background: #FFFFFF;
		border-radius: 30upx;
		margin: 31upx auto 0;

		.titlegl {
			font-size: 36upx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #000000;
			line-height: 50upx;
			padding: 20upx 23upx;
		}
	}

	.beanstyle {
		padding: 0 30upx;

		.title {
			font-size: 28upx;
			font-weight: 400;
			color: #050505;
			margin: 32upx 0 10upx;
		}

		font-size: 28upx;
		font-weight: 400;
		color: #818181;
	}

	.topbg {
		width: 750upx;
		height: 375upx;
		background: url(https://bsyjk-pic.bsyjk.cn/toprbg/10099E8526734AC383D6ADEED897F016.png)no-repeat;
		background-size: 750upx 375upx;
		padding-top: 108upx;
		box-sizing: border-box;
		position: relative;
		margin-bottom: 118upx;
	}

	.userView {
		width: 718upx;
		height: 179upx;
		padding: 30upx;
		background: #FFFFFF;
		box-shadow: 0px 2upx 20upx 0px rgba(173, 173, 173, 0.25);
		border-radius: 30upx;
		position: absolute;
		bottom: -84upx;
		left: 50%;
		transform: translateX(-50%);
		text-align: center;

		.userimg {
			width: 164upx;
			height: 164upx;
			display: block;
			border-radius: 50%;
			transform: translateY(-100upx);
			margin-bottom: -82upx;
			// background: pink;
			overflow: hidden;
		}
	}

	.newsStyle {
		width: 35upx;
		height: 39upx;
		background: url(http://static.bsyjk.cn/news/9010375A7C084342B6FE3E890C33F387.png) no-repeat;
		background-size: 35upx 39upx;
		position: relative;
		left: 130upx;

		.newsStylebf {
			display: inline-block;
			position: absolute;
			min-width: 30upx;
			min-height: 30upx;
			bottom: -16upx;
			right: -16upx;
			border-radius: 50upx;
			padding: 0upx 10upx;
			font-size: 20upx;
			font-weight: 400;
			color: #FFFFFF;
			line-height: 30upx;
			background: #FF333A;
		}
	}
</style>
